﻿using System;
using System.Runtime.Serialization;
using XcoAppSpaces.Contracts.Messaging;
using XcoAppSpaces.Core.Ports;

namespace XcoAppSpaces.Serialization.Binary
{
	class CausalityInfoSerializationSurrogate : ISerializationSurrogate
	{
		public void GetObjectData(object obj, SerializationInfo info, StreamingContext context)
		{
			var msg = (CausalityInfo)obj;
			info.AddValue("ExceptionPort", msg.ExceptionPort);
		}

		public object SetObjectData(object obj, SerializationInfo info, StreamingContext context, ISurrogateSelector selector)
		{
			obj = new CausalityInfo{ExceptionPort = (IPort<Exception>)info.GetValue("ExceptionPort", typeof(IPort<Exception>))};
			return obj;
		}
	}
}